package top.jidanmian.iot;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;

import lombok.extern.slf4j.Slf4j;
import top.jidanmian.iot.device.dao.DeviceEntityRepository;
import top.jidanmian.iot.device.entity.DeviceEntity;

@SpringBootApplication(exclude= {SecurityAutoConfiguration.class })
@Slf4j
public class ServerApplication {

	public static void main(String[] args) {
		SpringApplication.run(ServerApplication.class, args);
	}

	@Bean
	public CommandLineRunner demo(DeviceEntityRepository repository) {
		return (args) -> {
			repository.save(new DeviceEntity("灯", 
				"light-relay", "工作室", "OFF"));

			log.info("Deives found with findAll(): ");
			log.info("-----------------------------");
			repository.findAll().forEach(device -> {
				log.info(device.toString());
			});
			log.info("");

			
		};
	}
}
